# utils.py
from django.core.cache import cache
import random

def generate_verification_code(email):
    code = str(random.randint(100000, 999999))  # 6位数字验证码
    cache.set(f'pwd_reset_code_{email}', code, timeout=600)  # 10分钟有效期
    return code

def validate_verification_code(email, code):
    cached_code = cache.get(f'pwd_reset_code_{email}')
    return cached_code is not None and cached_code == code